#!/bin/bash
# 
# creates a JAR archive and a startup script then a ZIP file
# containing those as a distribution.
#
# copies files to a temporary folder to get rid of .svn folders 
# and then creates the jar
#
#

VER=0.2.0
WORK="/tmp/yatzybuild"
MAIN="net.andersand.games.yatzy.Yatzy"
CWD=`pwd`


# first make sure there are class files
CLASSFILES=`find . -name "*.class" -type f`
if [ -z "$CLASSFILES" ]; then
	echo "Failure: No class files found"
	exit 1
fi

if [ -d $WORK ]; then
	echo "Found directory $WORK"
	rm -rf $WORK/* # clean up
else
	echo "Didn't find directory $WORK, creating"
	mkdir $WORK
fi

echo -n "Copying files ..."
cp -R net $WORK
cp -R res $WORK
echo "DONE"

cd $WORK

echo -n "Creating manifest file ..."
echo -e "Main-Class: $MAIN" > MANIFEST.MF
echo "DONE"

echo -n "Deleting .svn folders ..."
find . -name ".svn" -type d -exec rm -rf {} \; &> /dev/null
echo "DONE"

echo -n "Creating JAR ..."
jar cmf MANIFEST.MF yatzy.jar res net
echo "DONE"

echo -n "Creating startup script ..."
echo -e "java -jar yatzy.jar" > start.bat
echo "DONE"

echo -n "Creating zipfile ..."
zip -q javayatzy-$VER.zip yatzy.jar start.bat
echo "DONE"

echo -n "Copying ZIP distribution back to $CWD ..."
cp javayatzy*.zip $CWD
echo "DONE"


